package com.dylan.channel.v5;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;

public class ServerBootstrap {


    volatile EventLoopGroup group;

    volatile EventLoopGroup childGroup;


    public ServerBootstrap group(EventLoopGroup parentGroup, EventLoopGroup childGroup) {
        this.group = parentGroup;
        this.childGroup = childGroup;
        return this;
    }

    public void bind(int port) throws IOException {
        this.bind(new InetSocketAddress(port));
    }

    private void bind(InetSocketAddress address) throws IOException {
        this.doBind(address);
    }

    private void doBind(InetSocketAddress address) throws IOException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        group.register(serverSocketChannel);
        serverSocketChannel.bind(address);
    }

}
